package com.example.link.controller;

import com.example.common.common.config.response.Page;
import com.example.link.model.CreateShortLinkDTO;
import com.example.link.model.LinkVO;
import com.example.link.service.LinkService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/8/17 14:18
 **/
@RestController
@RequestMapping("/api/link")
@RequiredArgsConstructor
public class LinkController {

    private final LinkService linkService;
    @PostMapping("/create")
    public void createShortLink(@RequestBody CreateShortLinkDTO createShortLinkDTO) {
        // 权限校验

        // 创建短链接
        linkService.createLink(createShortLinkDTO);
    }

    @GetMapping("/get")
    public Page<LinkVO> getShortLinks(@RequestParam("groupId") String groupId,
                                      @RequestParam("pageNum") int pageNum,
                                      @RequestParam("pageSize") int pageSize,
                                      @RequestParam("keyword") String keyword) {
        List<LinkVO> linkVOS = linkService.getShortLinks(groupId, pageNum, pageSize, keyword);
        return new Page<>(linkVOS.size(), pageNum, pageSize, linkVOS);
    }

}
